from fastapi import HTTPException
from typing import Any, Dict, Optional

class WebAPIException(HTTPException):
    """Web API自定义异常基类"""
    def __init__(
        self,
        status_code: int,
        detail: Any = None,
        headers: Optional[Dict[str, Any]] = None,
    ) -> None:
        super().__init__(status_code, detail, headers)

class BusStationException(WebAPIException):
    """公交站查询相关异常"""
    pass

class ImageProcessException(WebAPIException):
    """图片处理相关异常"""
    pass

class WeChatException(WebAPIException):
    """微信服务相关异常"""
    pass

class FileProcessException(WebAPIException):
    """文件处理相关异常"""
    pass

class AIServiceException(WebAPIException):
    """AI服务相关异常"""
    pass

# 常用异常快速创建函数
def not_found_exception(detail: str = "资源未找到"):
    return WebAPIException(status_code=404, detail=detail)

def bad_request_exception(detail: str = "请求参数错误"):
    return WebAPIException(status_code=400, detail=detail)

def internal_server_exception(detail: str = "服务器内部错误"):
    return WebAPIException(status_code=500, detail=detail)

def unauthorized_exception(detail: str = "未授权访问"):
    return WebAPIException(status_code=401, detail=detail)
